package com.flymobi.fw.util;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Mar 7, 2008 1:35:43 PM
 * @version $Id: NumberUtil.java,v 1.1 2008/03/26 06:24:07 airsou Exp $
 */
public class NumberUtil {
	private static final NumberFormat nf = NumberFormat
			.getInstance(Locale.CHINA);

	/**
	 * ��������
	 * @param value1
	 * @param value2
	 * @return
	 */
	public static boolean andOperate(int value1,int value2){
		if((value1 & value2)==value2){
			return true;
		}
		return false;
	}
	
	public static int toInt(String str) {
		int re = 0;
		if (!StringUtils.isEmpty(str)) {
			try {
				re = nf.parse(str).intValue();
			} catch (ParseException e) {
//				e.printStackTrace();
			}
		}
		return re;
	}
	
	public static double toDouble(String str) {
		double re = 0;
		if (!StringUtils.isEmpty(str)) {
			try {
				re = nf.parse(str).doubleValue();
			} catch (ParseException e) {
//				e.printStackTrace();
			}
		}
		return re;
	}
	
	public static int getRandomInt(int min,int max){
		return (int)Math.round(Math.random()*max+min);
	}
	
	public static int parseInt(String in){
		int re = 0;
		if(!StringUtils.isEmpty(in)){
			re = Integer.parseInt(in);
		}
		return re;
	}
	
	public static int[] parseInt(String[] in){
		int[] arr=new int[in.length];
		int i=0;
		for(String s:in){
			arr[i]=parseInt(s);
			i++;
		}
		return arr;
	}
	
	public static boolean isNumeric(String str)
	{
	    Pattern pattern = Pattern.compile("[0-9]*");
	    Matcher isNum = pattern.matcher(str);
	    if( !isNum.matches() ) {
	       return false;
	    }
	    return true;
	}
}
